package com.inforich.web.controller.projectManage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Arrays;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.projectManage.domain.ProjectRubbishDetail;
import com.inforich.projectManage.service.IProjectRubbishDetailService;
import com.inforich.common.utils.poi.ExcelUtil;

/**
 * 项目垃圾明细Controller
 *
 * @author hjm
 * @date 2022-10-30
 */
@RestController
@RequestMapping("/projectManage/projectRubbishdetail")
public class ProjectRubbishDetailController extends BaseController {

  @Autowired
  private IProjectRubbishDetailService projectRubbishDetailService;

  /**
   * 查询项目垃圾明细列表
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRubbishdetail:list')")
  @GetMapping("/list")
  public Page<ProjectRubbishDetail> list(Page<ProjectRubbishDetail> page,
      ProjectRubbishDetail projectRubbishDetail) {
    Map<String, Object> map = beanToMap(projectRubbishDetail);
    projectRubbishDetailService.pageProjectRubbishDetail(page, map);
    return page;
  }


  /**
   * 导出项目垃圾明细列表
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRubbishdetail:export')")
  @Log(title = "项目垃圾明细", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, ProjectRubbishDetail projectRubbishDetail) {
    Map<String, Object> map = beanToMap(projectRubbishDetail);
    List<ProjectRubbishDetail> list = projectRubbishDetailService.listProjectRubbishDetail(map);
    ExcelUtil<ProjectRubbishDetail> util = new ExcelUtil<ProjectRubbishDetail>(
        ProjectRubbishDetail.class);
    util.exportExcel(response, list, "项目垃圾明细数据");
  }

  /**
   * 获取项目垃圾明细详细信息
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRubbishdetail:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Integer id) {
    return AjaxResult.success(projectRubbishDetailService.getById(id));
  }

  /**
   * 新增项目垃圾明细
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRubbishdetail:add')")
  @Log(title = "项目垃圾明细", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@Validated @RequestBody ProjectRubbishDetail projectRubbishDetail) {
    return toAjax(projectRubbishDetailService.save(projectRubbishDetail));
  }

  /**
   * 修改项目垃圾明细
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRubbishdetail:edit')")
  @Log(title = "项目垃圾明细", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@Validated @RequestBody ProjectRubbishDetail projectRubbishDetail) {
    return toAjax(projectRubbishDetailService.updateById(projectRubbishDetail));
  }

  /**
   * 删除项目垃圾明细
   */
  @PreAuthorize("@ss.hasPermi('projectManage:projectRubbishdetail:remove')")
  @Log(title = "项目垃圾明细", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Integer[] ids) {
    return toAjax(projectRubbishDetailService.removeByIds(Arrays.asList(ids)));
  }

  /**
   * 根据项目ID查询
   */
  @GetMapping("/listByProjectId")
  public AjaxResult listByProjectId(String projectId) {
    return AjaxResult.success(
        projectRubbishDetailService.listProjectRubbishDetailByProjectId(projectId));
  }
}
